using System;
using System.ComponentModel;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Windows.Forms;

namespace ICP_MS.Plugin.SHINE;

public class FormAutoSampler : Form
{
	private IContainer components = null;

	private GroupBox groupBox5;

	private Button button15;

	private ComboBox cmbPort;

	private Label label34;

	private Label label1;

	private TextBox txtID;

	private GroupBox groupBox1;

	private TextBox txtVersion;

	private Label label2;

	private GroupBox groupBox2;

	private NumericUpDown nudPosition;

	private NumericUpDown nudTime;

	private NumericUpDown nudTimes;

	private Label label6;

	private Label label5;

	private Label label4;

	private TextBox txtPosition;

	private TextBox txtTime;

	private TextBox txtTimes;

	private ComboBox cmbStatus;

	private Label label3;

	private Button button8;

	private TextBox txtStatus;

	private Button btnStatusSet;

	private GroupBox groupBox3;

	private Label label9;

	private Label label7;

	private TextBox txtLeftTime;

	private TextBox txtLeftTimes;

	private Label label8;

	private Button button1;

	public FormAutoSampler()
	{
		InitializeComponent();
	}

	private void button15_Click(object sender, EventArgs e)
	{
		if (cmbPort.Text == "")
		{
			MessageBox.Show(Lang.Txt("SHFormAutoSampler.SelectSerial"));
			return;
		}
		if (SHAutoSampler.Instance.IsOpen)
		{
			SHAutoSampler.Instance.Close();
			if (SHAutoSampler.Instance.IsOpen)
			{
				button15.Text = Lang.Txt("SHFormAutoSampler.Close");
			}
			else
			{
				button15.Text = Lang.Txt("SHFormAutoSampler.Open");
			}
			return;
		}
		SHAutoSampler.Instance.Cominfo = new CommInfo();
		SHAutoSampler.Instance.Cominfo.Portname = cmbPort.Text;
		SHAutoSampler.Instance.Cominfo.Baudrate = 115200;
		SHAutoSampler.Instance.Cominfo.Parity = "None";
		SHAutoSampler.Instance.Cominfo.Databits = 8;
		SHAutoSampler.Instance.Cominfo.Stopbits = "One";
		if (SHAutoSampler.Instance.Init())
		{
			button15.Text = Lang.Txt("SHFormAutoSampler.Close");
		}
		else
		{
			button15.Text = Lang.Txt("SHFormAutoSampler.Open");
		}
	}

	private void btnStatusSet_Click(object sender, EventArgs e)
	{
		SHAutoSampler.Instance.SetStatus(new ushort[4]
		{
			(ushort)(cmbStatus.SelectedIndex + 1),
			(ushort)nudPosition.Value,
			(ushort)nudTime.Value,
			(ushort)nudTimes.Value
		});
	}

	private void button8_Click(object sender, EventArgs e)
	{
		ushort[] status = SHAutoSampler.Instance.ReadStatus();
		if (status != null)
		{
			txtStatus.Text = ((status[0] == 0) ? Lang.Txt("SHFormAutoSampler.Wait") : ((status[0] == 1) ? Lang.Txt("SHFormAutoSampler.SampleEnters") : Lang.Txt("SHFormAutoSampler.Initialization")));
			txtPosition.Text = status[1].ToString();
			txtTime.Text = status[2].ToString();
			txtTimes.Text = status[3].ToString();
			txtLeftTime.Text = status[4].ToString();
			txtLeftTimes.Text = status[5].ToString();
		}
	}

	private void cmbPort_SelectedIndexChanged(object sender, EventArgs e)
	{
	}

	private void FormAutoSampler_Load(object sender, EventArgs e)
	{
		ApplyResources();
		if (SHAutoSampler.Instance.IsOpen)
		{
			button15.Text = Lang.Txt("SHFormAutoSampler.Close");
		}
		else
		{
			button15.Text = Lang.Txt("SHFormAutoSampler.Open");
		}
		string[] names = SerialPort.GetPortNames();
		if (names != null && names.Count() > 0)
		{
			for (int i = 0; i < names.Count(); i++)
			{
				cmbPort.Items.Add(names[i]);
			}
			cmbPort.SelectedIndex = 0;
		}
		if (SHAutoSampler.Instance.Cominfo != null && cmbPort.Items.Contains(SHAutoSampler.Instance.Cominfo.Portname))
		{
			cmbPort.Text = SHAutoSampler.Instance.Cominfo.Portname;
		}
	}

	private void ApplyResources()
	{
		Text = Lang.Txt("SHFormAutoSampler.SAutosampler");
		groupBox5.Text = Lang.Txt("SHFormAutoSampler.AdvancedSettings");
		label34.Text = Lang.Txt("SHFormAutoSampler.SerialNum");
		button15.Text = Lang.Txt("SHFormAutoSampler.Open");
		groupBox1.Text = Lang.Txt("SHFormAutoSampler.DeviceInformation");
		label1.Text = Lang.Txt("SHFormAutoSampler.Numbering");
		label2.Text = Lang.Txt("SHFormAutoSampler.Version");
		button1.Text = Lang.Txt("SHFormAutoSampler.Inquire");
		button8.Text = Lang.Txt("SHFormAutoSampler.Inquire");
		groupBox2.Text = Lang.Txt("SHFormAutoSampler.Settings");
		groupBox3.Text = Lang.Txt("SHFormAutoSampler.Settings");
		label3.Text = Lang.Txt("SHFormAutoSampler.InstrumentState");
		label6.Text = Lang.Txt("SHFormAutoSampler.InjectionLocation");
		label4.Text = Lang.Txt("SHFormAutoSampler.InjectionTime");
		label5.Text = Lang.Txt("SHFormAutoSampler.Cycles");
		btnStatusSet.Text = Lang.Txt("SHFormAutoSampler.Set");
		label7.Text = Lang.Txt("SHFormAutoSampler.TimeLeft");
		label8.Text = Lang.Txt("SHFormAutoSampler.RemainingTimes");
	}

	private void button1_Click_1(object sender, EventArgs e)
	{
		if (SHAutoSampler.Instance.IsOpen)
		{
			ushort[] ss = SHAutoSampler.Instance.ReadInstrumentID();
			if (ss != null)
			{
				txtID.Text = ss[0].ToString();
				txtVersion.Text = ss[1].ToString();
			}
		}
	}

	protected override void Dispose(bool disposing)
	{
		if (disposing && components != null)
		{
			components.Dispose();
		}
		base.Dispose(disposing);
	}

	private void InitializeComponent()
	{
		this.groupBox5 = new System.Windows.Forms.GroupBox();
		this.button15 = new System.Windows.Forms.Button();
		this.cmbPort = new System.Windows.Forms.ComboBox();
		this.label34 = new System.Windows.Forms.Label();
		this.label1 = new System.Windows.Forms.Label();
		this.txtID = new System.Windows.Forms.TextBox();
		this.groupBox1 = new System.Windows.Forms.GroupBox();
		this.txtVersion = new System.Windows.Forms.TextBox();
		this.label2 = new System.Windows.Forms.Label();
		this.button1 = new System.Windows.Forms.Button();
		this.groupBox2 = new System.Windows.Forms.GroupBox();
		this.cmbStatus = new System.Windows.Forms.ComboBox();
		this.label3 = new System.Windows.Forms.Label();
		this.txtTimes = new System.Windows.Forms.TextBox();
		this.txtTime = new System.Windows.Forms.TextBox();
		this.txtStatus = new System.Windows.Forms.TextBox();
		this.txtPosition = new System.Windows.Forms.TextBox();
		this.nudPosition = new System.Windows.Forms.NumericUpDown();
		this.nudTime = new System.Windows.Forms.NumericUpDown();
		this.nudTimes = new System.Windows.Forms.NumericUpDown();
		this.label6 = new System.Windows.Forms.Label();
		this.label5 = new System.Windows.Forms.Label();
		this.label4 = new System.Windows.Forms.Label();
		this.button8 = new System.Windows.Forms.Button();
		this.btnStatusSet = new System.Windows.Forms.Button();
		this.groupBox3 = new System.Windows.Forms.GroupBox();
		this.label9 = new System.Windows.Forms.Label();
		this.label7 = new System.Windows.Forms.Label();
		this.txtLeftTime = new System.Windows.Forms.TextBox();
		this.txtLeftTimes = new System.Windows.Forms.TextBox();
		this.label8 = new System.Windows.Forms.Label();
		this.groupBox5.SuspendLayout();
		this.groupBox1.SuspendLayout();
		this.groupBox2.SuspendLayout();
		((System.ComponentModel.ISupportInitialize)this.nudPosition).BeginInit();
		((System.ComponentModel.ISupportInitialize)this.nudTime).BeginInit();
		((System.ComponentModel.ISupportInitialize)this.nudTimes).BeginInit();
		this.groupBox3.SuspendLayout();
		base.SuspendLayout();
		this.groupBox5.Controls.Add(this.button15);
		this.groupBox5.Controls.Add(this.cmbPort);
		this.groupBox5.Controls.Add(this.label34);
		this.groupBox5.Location = new System.Drawing.Point(12, 12);
		this.groupBox5.Name = "groupBox5";
		this.groupBox5.Size = new System.Drawing.Size(487, 55);
		this.groupBox5.TabIndex = 10;
		this.groupBox5.TabStop = false;
		this.groupBox5.Text = "高级设置";
		this.button15.Location = new System.Drawing.Point(352, 19);
		this.button15.Name = "button15";
		this.button15.Size = new System.Drawing.Size(113, 30);
		this.button15.TabIndex = 2;
		this.button15.Text = "打开";
		this.button15.UseVisualStyleBackColor = true;
		this.button15.Click += new System.EventHandler(button15_Click);
		this.cmbPort.FormattingEnabled = true;
		this.cmbPort.Location = new System.Drawing.Point(175, 24);
		this.cmbPort.Name = "cmbPort";
		this.cmbPort.Size = new System.Drawing.Size(113, 23);
		this.cmbPort.TabIndex = 1;
		this.cmbPort.SelectedIndexChanged += new System.EventHandler(cmbPort_SelectedIndexChanged);
		this.label34.AutoSize = true;
		this.label34.Location = new System.Drawing.Point(30, 27);
		this.label34.Name = "label34";
		this.label34.Size = new System.Drawing.Size(67, 15);
		this.label34.TabIndex = 1;
		this.label34.Text = "串口号：";
		this.label1.AutoSize = true;
		this.label1.Location = new System.Drawing.Point(15, 35);
		this.label1.Name = "label1";
		this.label1.Size = new System.Drawing.Size(82, 15);
		this.label1.TabIndex = 1;
		this.label1.Text = "设备编号：";
		this.txtID.Location = new System.Drawing.Point(175, 30);
		this.txtID.Name = "txtID";
		this.txtID.Size = new System.Drawing.Size(113, 25);
		this.txtID.TabIndex = 11;
		this.groupBox1.Controls.Add(this.txtVersion);
		this.groupBox1.Controls.Add(this.label2);
		this.groupBox1.Controls.Add(this.txtID);
		this.groupBox1.Controls.Add(this.label1);
		this.groupBox1.Controls.Add(this.button1);
		this.groupBox1.Location = new System.Drawing.Point(12, 73);
		this.groupBox1.Name = "groupBox1";
		this.groupBox1.Size = new System.Drawing.Size(487, 101);
		this.groupBox1.TabIndex = 12;
		this.groupBox1.TabStop = false;
		this.groupBox1.Text = "设备信息";
		this.txtVersion.Location = new System.Drawing.Point(175, 61);
		this.txtVersion.Name = "txtVersion";
		this.txtVersion.Size = new System.Drawing.Size(113, 25);
		this.txtVersion.TabIndex = 11;
		this.label2.AutoSize = true;
		this.label2.Location = new System.Drawing.Point(15, 65);
		this.label2.Name = "label2";
		this.label2.Size = new System.Drawing.Size(82, 15);
		this.label2.TabIndex = 1;
		this.label2.Text = "硬件版本：";
		this.button1.Location = new System.Drawing.Point(352, 35);
		this.button1.Name = "button1";
		this.button1.Size = new System.Drawing.Size(113, 30);
		this.button1.TabIndex = 2;
		this.button1.Text = "查询";
		this.button1.UseVisualStyleBackColor = true;
		this.button1.Click += new System.EventHandler(button1_Click_1);
		this.groupBox2.Controls.Add(this.cmbStatus);
		this.groupBox2.Controls.Add(this.label3);
		this.groupBox2.Controls.Add(this.txtTimes);
		this.groupBox2.Controls.Add(this.txtTime);
		this.groupBox2.Controls.Add(this.txtStatus);
		this.groupBox2.Controls.Add(this.txtPosition);
		this.groupBox2.Controls.Add(this.nudPosition);
		this.groupBox2.Controls.Add(this.nudTime);
		this.groupBox2.Controls.Add(this.nudTimes);
		this.groupBox2.Controls.Add(this.label6);
		this.groupBox2.Controls.Add(this.label5);
		this.groupBox2.Controls.Add(this.label4);
		this.groupBox2.Location = new System.Drawing.Point(12, 180);
		this.groupBox2.Name = "groupBox2";
		this.groupBox2.Size = new System.Drawing.Size(346, 173);
		this.groupBox2.TabIndex = 12;
		this.groupBox2.TabStop = false;
		this.groupBox2.Text = "设置";
		this.cmbStatus.FormattingEnabled = true;
		this.cmbStatus.Items.AddRange(new object[2] { "1-进样", "2-初始化" });
		this.cmbStatus.Location = new System.Drawing.Point(175, 24);
		this.cmbStatus.Name = "cmbStatus";
		this.cmbStatus.Size = new System.Drawing.Size(83, 23);
		this.cmbStatus.TabIndex = 1;
		this.label3.AutoSize = true;
		this.label3.Location = new System.Drawing.Point(15, 27);
		this.label3.Name = "label3";
		this.label3.Size = new System.Drawing.Size(82, 15);
		this.label3.TabIndex = 1;
		this.label3.Text = "仪器状态：";
		this.txtTimes.Location = new System.Drawing.Point(264, 134);
		this.txtTimes.Name = "txtTimes";
		this.txtTimes.Size = new System.Drawing.Size(82, 25);
		this.txtTimes.TabIndex = 11;
		this.txtTime.Location = new System.Drawing.Point(264, 95);
		this.txtTime.Name = "txtTime";
		this.txtTime.Size = new System.Drawing.Size(82, 25);
		this.txtTime.TabIndex = 11;
		this.txtStatus.Location = new System.Drawing.Point(264, 24);
		this.txtStatus.Name = "txtStatus";
		this.txtStatus.Size = new System.Drawing.Size(82, 25);
		this.txtStatus.TabIndex = 11;
		this.txtPosition.Location = new System.Drawing.Point(264, 59);
		this.txtPosition.Name = "txtPosition";
		this.txtPosition.Size = new System.Drawing.Size(82, 25);
		this.txtPosition.TabIndex = 11;
		this.nudPosition.Location = new System.Drawing.Point(175, 59);
		this.nudPosition.Maximum = new decimal(new int[4] { 40, 0, 0, 0 });
		this.nudPosition.Minimum = new decimal(new int[4] { 1, 0, 0, 0 });
		this.nudPosition.Name = "nudPosition";
		this.nudPosition.Size = new System.Drawing.Size(83, 25);
		this.nudPosition.TabIndex = 12;
		this.nudPosition.Value = new decimal(new int[4] { 1, 0, 0, 0 });
		this.nudTime.Location = new System.Drawing.Point(175, 95);
		this.nudTime.Maximum = new decimal(new int[4] { 60, 0, 0, 0 });
		this.nudTime.Minimum = new decimal(new int[4] { 3, 0, 0, 0 });
		this.nudTime.Name = "nudTime";
		this.nudTime.Size = new System.Drawing.Size(83, 25);
		this.nudTime.TabIndex = 12;
		this.nudTime.Value = new decimal(new int[4] { 3, 0, 0, 0 });
		this.nudTimes.Location = new System.Drawing.Point(175, 135);
		this.nudTimes.Maximum = new decimal(new int[4] { 6, 0, 0, 0 });
		this.nudTimes.Minimum = new decimal(new int[4] { 1, 0, 0, 0 });
		this.nudTimes.Name = "nudTimes";
		this.nudTimes.Size = new System.Drawing.Size(83, 25);
		this.nudTimes.TabIndex = 12;
		this.nudTimes.Value = new decimal(new int[4] { 1, 0, 0, 0 });
		this.label6.AutoSize = true;
		this.label6.Location = new System.Drawing.Point(15, 62);
		this.label6.Name = "label6";
		this.label6.Size = new System.Drawing.Size(82, 15);
		this.label6.TabIndex = 1;
		this.label6.Text = "进样位置：";
		this.label5.AutoSize = true;
		this.label5.Location = new System.Drawing.Point(15, 141);
		this.label5.Name = "label5";
		this.label5.Size = new System.Drawing.Size(82, 15);
		this.label5.TabIndex = 1;
		this.label5.Text = "循环次数：";
		this.label4.AutoSize = true;
		this.label4.Location = new System.Drawing.Point(15, 101);
		this.label4.Name = "label4";
		this.label4.Size = new System.Drawing.Size(82, 15);
		this.label4.TabIndex = 1;
		this.label4.Text = "进样时间：";
		this.button8.Location = new System.Drawing.Point(364, 300);
		this.button8.Name = "button8";
		this.button8.Size = new System.Drawing.Size(113, 30);
		this.button8.TabIndex = 2;
		this.button8.Text = "查询";
		this.button8.UseVisualStyleBackColor = true;
		this.button8.Click += new System.EventHandler(button8_Click);
		this.btnStatusSet.Location = new System.Drawing.Point(364, 246);
		this.btnStatusSet.Name = "btnStatusSet";
		this.btnStatusSet.Size = new System.Drawing.Size(113, 30);
		this.btnStatusSet.TabIndex = 2;
		this.btnStatusSet.Text = "设置";
		this.btnStatusSet.UseVisualStyleBackColor = true;
		this.btnStatusSet.Click += new System.EventHandler(btnStatusSet_Click);
		this.groupBox3.Controls.Add(this.label9);
		this.groupBox3.Controls.Add(this.label7);
		this.groupBox3.Controls.Add(this.txtLeftTime);
		this.groupBox3.Controls.Add(this.txtLeftTimes);
		this.groupBox3.Controls.Add(this.label8);
		this.groupBox3.Location = new System.Drawing.Point(12, 359);
		this.groupBox3.Name = "groupBox3";
		this.groupBox3.Size = new System.Drawing.Size(325, 91);
		this.groupBox3.TabIndex = 12;
		this.groupBox3.TabStop = false;
		this.groupBox3.Text = "设置";
		this.label9.AutoSize = true;
		this.label9.Location = new System.Drawing.Point(275, 27);
		this.label9.Name = "label9";
		this.label9.Size = new System.Drawing.Size(31, 15);
		this.label9.TabIndex = 1;
		this.label9.Text = "min";
		this.label7.AutoSize = true;
		this.label7.Location = new System.Drawing.Point(15, 27);
		this.label7.Name = "label7";
		this.label7.Size = new System.Drawing.Size(82, 15);
		this.label7.TabIndex = 1;
		this.label7.Text = "剩余时间：";
		this.txtLeftTime.Location = new System.Drawing.Point(175, 24);
		this.txtLeftTime.Name = "txtLeftTime";
		this.txtLeftTime.Size = new System.Drawing.Size(83, 25);
		this.txtLeftTime.TabIndex = 11;
		this.txtLeftTimes.Location = new System.Drawing.Point(175, 58);
		this.txtLeftTimes.Name = "txtLeftTimes";
		this.txtLeftTimes.Size = new System.Drawing.Size(83, 25);
		this.txtLeftTimes.TabIndex = 11;
		this.label8.AutoSize = true;
		this.label8.Location = new System.Drawing.Point(15, 62);
		this.label8.Name = "label8";
		this.label8.Size = new System.Drawing.Size(82, 15);
		this.label8.TabIndex = 1;
		this.label8.Text = "剩余次数：";
		base.AutoScaleDimensions = new System.Drawing.SizeF(8f, 15f);
		base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
		base.ClientSize = new System.Drawing.Size(518, 497);
		base.Controls.Add(this.groupBox3);
		base.Controls.Add(this.groupBox2);
		base.Controls.Add(this.groupBox1);
		base.Controls.Add(this.groupBox5);
		base.Controls.Add(this.button8);
		base.Controls.Add(this.btnStatusSet);
		base.Name = "FormAutoSampler";
		base.ShowIcon = false;
		this.Text = "自动进样器";
		base.Load += new System.EventHandler(FormAutoSampler_Load);
		this.groupBox5.ResumeLayout(false);
		this.groupBox5.PerformLayout();
		this.groupBox1.ResumeLayout(false);
		this.groupBox1.PerformLayout();
		this.groupBox2.ResumeLayout(false);
		this.groupBox2.PerformLayout();
		((System.ComponentModel.ISupportInitialize)this.nudPosition).EndInit();
		((System.ComponentModel.ISupportInitialize)this.nudTime).EndInit();
		((System.ComponentModel.ISupportInitialize)this.nudTimes).EndInit();
		this.groupBox3.ResumeLayout(false);
		this.groupBox3.PerformLayout();
		base.ResumeLayout(false);
	}
}
